package bitmap
{
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	/**
	 *  位图影片剪辑
	 * @author Devin
	 */
	public class BitmapMovieClip
	{
		private var _totalFrames:int;
		private var _isPlaying:Boolean;
		private var _frameIndex:int=0;
		private var _currentFrame:BitmapFrame;
		private var _visible:Boolean = true;
		private var _x: Number = 0;
		private var _y: Number = 0;
		private var _z: Number = NaN;
		private var _colorTransform:ColorTransform = null;
		private var _rotation:Number = 0;
		private var _blendMode:String = null;
		private var _scaleX:Number = 1;
		private var _scaleY:Number = 1;
		private var _bitmapAnimation:BitmapAnimation;
		
		/**
		 *  位图影片剪辑
		 * @param bitmapAnimation 动画对象
		 * 
		 */	
		public function BitmapMovieClip(bitmapAnimation:BitmapAnimation)
		{
			_bitmapAnimation=bitmapAnimation;
			_totalFrames=_bitmapAnimation.totalFrames;
			_currentFrame = _bitmapAnimation.frames[_frameIndex];
		}
		
		public function update():void
		{
			updateFrame();
		}
		
		private function updateFrame():void
		{
			if(_isPlaying)
			{
				if (_frameIndex >= _totalFrames)
				{
					_frameIndex = 1;
				}else
				{
					_frameIndex ++;
				}
			}
			_currentFrame = _bitmapAnimation.frames[_frameIndex-1];
		}
		
		public function play():void
		{
			isPlaying = true;
		}
		
		public function stop():void
		{
			isPlaying = false;
		}
		
		/**
		 *总帧数 
		 */		
		public function get totalFrames():int
		{
			return _totalFrames;
		}
		
		public function get isPlaying():Boolean
		{
			return _isPlaying;
		}
		
		public function set isPlaying(value:Boolean):void
		{
			_isPlaying = value;
		}
		
		public function get frameIndex():int
		{
			return _frameIndex;
		}
		
		public function get currentFrame():BitmapFrame
		{
			return _currentFrame;
		}
		
		public function get visible():Boolean
		{
			return _visible;
		}
		
		public function set visible(value:Boolean):void
		{
			_visible = value;
		}
		
		public function get x():Number
		{
			return _x;
		}
		
		public function set x(value:Number):void
		{
			_x = value;
		}
		
		public function get y():Number
		{
			return _y;
		}
		
		public function set y(value:Number):void
		{
			_y = value;
		}
		
		public function get z():Number
		{
			return _z;
		}
		
		public function set z(value:Number):void
		{
			_z = value;
		}
		
		public function get colorTransform():ColorTransform
		{
			return _colorTransform;
		}
		
		public function get rotation():Number
		{
			return _rotation;
		}
		
		public function get blendMode():String
		{
			return _blendMode;
		}
		
		public function get scaleX():Number
		{
			return _scaleX;
		}
		
		public function get scaleY():Number
		{
			return _scaleY;
		}
		
		public function set scaleY(value:Number):void
		{
			_scaleY = value;
		}
		
		public function set scaleX(value:Number):void
		{
			_scaleX = value;
		}
		
		public function set blendMode(value:String):void
		{
			_blendMode = value;
		}
		
		public function set rotation(value:Number):void
		{
			_rotation = value;
		}
		
		public function clone():BitmapMovieClip
		{
			return new BitmapMovieClip(_bitmapAnimation);
		}
		
		/**
		 *释放资源 
		 */	
		public function dispose():void
		{
			_currentFrame=null;
			_colorTransform=null;
			_bitmapAnimation=null;
		}
	}
}